package com.laowang.project.system.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyArticle;
import com.laowang.project.system.service.MyArticleService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 介绍信息Controller
 *
 * @author laowang
 * @date 2023-05-17
 */
@Api(tags = "介绍信息接口")
@RestController
@RequestMapping("/article")
public class MyArticleController extends BaseController {
    @Autowired
    private MyArticleService myArticleService;


    /**
     * 查询介绍信息列表
     */
    @ApiOperation(value = "小程序端 查询介绍信息列表",notes = "")
    @GetMapping("web/{id}")
    public AjaxResult webId(@PathVariable Integer id) {

        MyArticle myArticle = myArticleService.selectMyArticleById(id);
        return AjaxResult.success("操作成功",myArticle);
    }

    /**
     * 查询介绍信息列表
     */
    @ApiOperation(value = "查询介绍信息列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyArticle myArticle) {
        startPage();
        List<MyArticle> list = myArticleService.selectMyArticleList(myArticle);
        return getDataTable(list);
    }

    /**
     * 导出介绍信息列表
     */
    @ApiOperation(value = "导出介绍信息列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:article:export')")
    @Log(title = "介绍信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyArticle myArticle) {
        List<MyArticle> list = myArticleService.selectMyArticleList(myArticle);
        ExcelUtil<MyArticle> util = new ExcelUtil<MyArticle>(MyArticle.class);
        return util.exportExcel(list, "article");
    }

    /**
     * 获取介绍信息详细信息
     */
    @ApiOperation(value = "获取介绍信息详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:article:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myArticleService.selectMyArticleById(id));
    }

    /**
     * 新增介绍信息
     */
    @ApiOperation(value = "新增介绍信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:article:add')")
    @Log(title = "介绍信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyArticle myArticle) {
        return toAjax(myArticleService.insertMyArticle(myArticle));
    }

    /**
     * 修改介绍信息
     */
    @ApiOperation(value = "修改介绍信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:article:edit')")
    @Log(title = "介绍信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyArticle myArticle) {
        return toAjax(myArticleService.updateMyArticle(myArticle));
    }

    /**
     * 删除介绍信息
     */
    @ApiOperation(value = "删除介绍信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:article:remove')")
    @Log(title = "介绍信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myArticleService.deleteMyArticleByIds(ids));
    }
}
